﻿using UnityEngine;
using System.Collections;

public class VolumeManager : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	UISlider slider;	
	public UIToggle soundToggle;

	void Awake()
	{
		// Get the Slider
		slider = GetComponent<UISlider>();
		// Set the Slider's value to last saved volume.
		slider.value = NGUITools.soundVolume;
		
		if(NGUITools.soundVolume ==0)
			soundToggle.value = false;
	}
	
	public void onVolumeChange()
	{
		NGUITools.soundVolume = UISlider.current.value;
		
		AudioListener.volume = UISlider.current.value;
	}	
	
	public void onSoundToggle()
	{
		float newVolume = 0;
		if(UIToggle.current.value)
		{
			newVolume = slider.value;
		}
		
		AudioListener.volume = newVolume;
		NGUITools.soundVolume = newVolume;
	}
}
